format PE GUI 4.0 at DefImageBase on '..\include\mx_stub.exe'

include '%fasminc%\win32ax.inc'
;include "..\Include\macros.inc"
include "..\Include\data.inc"
include "..\Include\const.inc"
include "..\Include\struct.inc"

win_color       = 0x666666
x_size          = 200
y_size          = 100

Head_YSize      = 0x16
Head_Color      = 0x80

Resize_XSize    = 10
Resize_YSize    = 10
Resize_offset   = 2

Client_Color    = 0x01F0D0

default_buttons = 00000b

  start:

   ; reading parametres...

        mov     eax,MessageText
        call    read_param
        mov     eax,my_name
        call    read_param

   ; center

        call    [Get_screen_param]
	shr	esi,1
	shr	edi,1
        sub     esi,x_size/2
        sub     edi,y_size/2
	shl	esi,16
	or	esi,edi
        mov     [Default_XY],esi
        mov     [Default_XYSize],x_size*65536+y_size

        call    Redraw

        mov     ecx,0
        
      Wait_Event:
        call    [WaitMessage]
        call    [StdHandler]

        cmp     bx,(EventID_Ctrl3 shl 8) + 1
        jne     no_pressbutton
        call    Unload
      no_pressbutton:


        cmp     bh,EventID_Kbd
        jne     no_kbd
        shr     si,8    
        cmp     si,0x1C
        jne     no_enter
        call    Unload
      no_enter:

      no_kbd:

        jmp     Wait_Event

Unload:
        invoke  Kill_Window, [WinID]
        invoke  ExitProcess, 0
        ret

bttn_xsize      = 70
bttn_ysize      = 25
bttn_yoffset    = 18
xy_button       = ((x_size/2)-(bttn_xsize/2))*65536+(y_size-bttn_ysize-bttn_yoffset)

Redraw:
        mov     eax,my_name
        cmp     [eax],byte 0
        je      default_name
        jmp     no_default_name
      default_name:
        mov     eax,def_my_name
      no_default_name:
        invoke  Draw_StdWindow, [Default_XY],[Default_XYSize],eax,[Buttons]
        mov     [WinID],eax
        invoke  WriteText,15,0x16+10,1,4,MessageText
        invoke  Create_StdButton, xy_button,bttn_xsize*65536+bttn_ysize,btext,1,10b
        call    [End_of_redraw]
        ret

; IN  : EAX - Buffer
read_param:
      reading_param:
        push    eax
        call    [ReceiveMessage]
        pop     eax
        cmp     bh,0
        je      reading_param

        mov     [eax],esi
        cmp     esi,0
        je      exit_reading_param
        add     eax,4
        mov     [eax],ebp
        cmp     ebp,0
        je      exit_reading_param
        add     eax,4
        jmp     reading_param
      exit_reading_param:
        
        ret

EventID_Redraw          = 1
EventID_Focus           = 2
EventID_LostFocus       = 3
EventID_Close           = 4
EventID_MouseEvent      = 5
EventID_Ctrl0           = 10
EventID_Ctrl1           = 11
EventID_Ctrl2           = 12
EventID_Ctrl3           = 13
EventID_Maximize        = 14
EventID_Restore         = 15
EventID_Kbd             = 20
EventID_IPC             = 50

; Reserved ctrl:
CtrlID_Moving           = 0xFF
CtrlID_CSize            = 0xFE

data import
;
; Import functions:
;

  library mx32,'mx32.dll'

  import mx32,\
         f1,'OneFunction',\
         VirtualAlloc,'VirtualAlloc',\
         VirtualProtect,'VirtualProtect',\
         VirtualFree,'VirtualFree',\
         CreateProcess,'CreateProcess',\
         ExitProcess,'ExitProcess',\
         CreateThread,'CreateThread',\
         ExitThread,'ExitThread',\
         TestKbdInput,'TestKbdInput',\
         PutChar,'PutChar',\
         PutChar2,'PutChar2',\
         PrintString,'PrintString',\
         Get_Position,'Get_Position',\
         Set_Position,'Set_Position',\
         Set_focus,'Set_focus',\
         Set_focusPID,'Set_focusPID',\
         Get_FileAddress,'Get_FileAddress',\
         Inkey,'Inkey',\
         SendMessage,'SendMessage',\
         ReceiveMessage,'ReceiveMessage',\
         WaitMessage,'WaitMessage',\
         GetPID,'GetPID',\
         DefineWindow,'DefineWindow',\
         DefineButton,'DefineButton',\
         Put_pixel,'Put_pixel',\
         Get_screen_param,'Get_screen_param',\
         Draw_BLine,'Draw_BLine',\
         Draw_Picture,'Draw_Picture',\
         Kill_Window,'Kill_Window',\
         Write_Text,'Write_Text',\
         WriteText,'WriteText',\
         Write_Hex,'Write_Hex',\
         Draw_StdWindow,'Draw_StdWindow',\
         StdHandler,'StdHandler',\
         Draw_hLine,'Draw_hLine',\
         Get_XYSize,'Get_XYSize',\
         Get_WinParams,'Get_WinParams',\
         End_of_redraw,'End_of_redraw',\
         Begin_xDraw,'Begin_xDraw',\
         Get_focus,'Get_focus',\
         Create_CheckButton,'Create_CheckButton',\
         Create_StdButton,'Create_StdButton'


 
end data

section '.rsrc' resource data readable

  ; resource directory

  directory RT_ICON,icons,\
            RT_GROUP_ICON,group_icons,\
            RT_VERSION,versions

  ; resource subdirectories

  resource icons,\
           1,LANG_NEUTRAL,icon_data

  resource group_icons,\
           17,LANG_NEUTRAL,main_icon

  resource versions,\
           1,LANG_NEUTRAL,version

  icon main_icon,icon_data,'..\include\mx.ico'

  versioninfo version,\
          VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
          'FileDescription','Message Box Thread',\
          'FileVersion','1.0',\
          'OriginalFilename','MSGBOX.EXE',\
          'InternalName','MsgBox.exe',\
          'SpecialBuild',SpecialBuild,\
          'ProductName',ProductName,\
          'ProductVersion',ProductVersion,\
          'LegalCopyright',LegalCopyright,\
          'CompanyName',CompanyName,\
          'Comments',rsrcComments,\
          'LegalTrademarks',LegalTrademarks

section '.data' data readable writeable
  btext                 db 'OK',0
  def_my_name           db 'message',0

  Buttons               dd default_buttons
  Default_XY            rd 1
  Default_XYSize        rd 1
  WinID                 rd 1
  my_name               rb 0x1000
  MessageText           rb 0x1000
